// 导入全局样式表
import '@/assets/css/globel.css'
import Vue from 'vue'
import routes from './routes'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
const router = new VueRouter({
  mode: 'history',
  routes
})
// 权限判断 全局路由守卫
const powerPath = ['/home'] // 权限判断的路由
router.beforeEach((to, from, next) => {
  // to 将要跳转的路径
  // from 代表从那个路径跳转而来
  // next 是一个函数，表示放行
  // next() 放行， next('/login')
  if (powerPath.includes(to.path)) {
    // 如果包含则打印 yes
    const tokenStr = window.sessionStorage.getItem('token')
    if (!tokenStr) return next('/login')
    next()
  }
  next()
})
export default router
